<template>
  <el-drawer :visible.sync="drawer" direction="rtl" size="50%" :with-header="false" :width="700">
    <div class="drawer_box">
      <div class="drawer_title">
        <div class="drawer_t">
          <div class="drawer_t_l">
            <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/piliangoumai.png" alt="" />
            查看城市活动
          </div>
          <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
            @click="drawer = false" />
        </div>
      </div>
      <div class="tab">
        <div @click="tabIndex = 0">主题活动信息</div>
        <div @click="tabIndex = 1">打卡情况</div>
      </div>
      <div class="drawer_content" v-if="tabIndex == 0">
        <div class="list-box">
          <div class="left">城市活动主题：</div>
          <div class="right">
            {{ detail.ThemeName }}
          </div>
        </div>

        <div class="list-box">
          <div class="left">城市活动名称：</div>
          <div class="right">
            {{ detail.Name }}
          </div>
        </div>

        <div class="list-box" v-if="drawer">
          <div class="left"></div>
          <div class="right boxinfo">
            <img class="big-img" :src="getImgUrl.url" />
            <div v-for="(item, i) in pointList" :key="i" :style="{
              top: item.sy + 'px',
              left: item.sx + 'px',
              width: item.pw + 'px'
            }" :class="`small-box img${i + 1}`">
              <img class="small" src="/static/skin/default/MCS/AIGC/Inventory/images/point1.png" alt="" />
              <span>{{ i + 1 }}</span>
            </div>
          </div>
        </div>

        <div class="list-box">
          <div class="left">打卡点：</div>
          <div class="right">
            <div v-for="(item, i) in pointList" :key="item.id">
              <div class="row">
                <div class="point">
                  <img src="/static/skin/default/MCS/AIGC/Inventory/images/point1.png" />
                  <span>{{ i + 1 }}</span>
                </div>
                <span class="name">{{ item.Name }}</span>
                <span class="lat">左边距: <span>{{ item.x }}</span> 像素</span>
                <span class="lat">上边距: <span>{{ item.y }}</span> 像素</span>
              </div>
            </div>
          </div>
        </div>

        <!-- <div class="list-box">
          <div class="left">打卡规则：</div>
          <div class="right">
            {{ detail.TypeID }}
          </div>
        </div> -->

        <div class="list-box">
          <div class="left">打卡顺序:</div>
          <div class="right">
            <el-radio-group v-model="detail.SortTypeID" @input="changeRadio" :disabled="true">
              <el-radio label="1">无序打卡</el-radio>
              <el-radio label="2">顺序打卡</el-radio>
            </el-radio-group>
            <div class="small">
              无序打卡:小程序用户无需按照添加打卡点的顺序进行打卡
            </div>
            <div class="small">
              顺序打卡:小程序用户打卡时将必须按照添加打卡点的顺序进行打卡，否则无法打卡。
            </div>
          </div>
        </div>

        <div class="list-box">
          <div class="left">主题活动勋章：</div>
          <div class="right">
            <div class="medal">
              <img :src="getMedal && getMedal.url" alt="" />
              <span>{{ detail.BadgeName }}</span>
            </div>
          </div>
        </div>

        <div class="list-box">
          <div class="left">线下领奖经纬度：</div>
          <div class="right">{{ detail.XAxis }} , {{ detail.YAxis }}</div>
        </div>

        <div class="list-box">
          <div class="left">线下领奖地址：</div>
          <div class="right">
            {{ detail.Address }}
          </div>
        </div>

        <div class="list-box">
          <div class="left">城市活动详情：</div>
          <div class="right">
            <div v-html="detail.Description"></div>
          </div>
        </div>
      </div>
      <div class="drawer_content" v-if="tabIndex == 1">
        <div class="list-box">
          <div class="left">参加打卡人数：</div>
          <div class="right">
            {{ info.ApplyNbm }}
          </div>
        </div>
        <div class="list-box">
          <div class="left">完成打卡人数：</div>
          <div class="right">
            {{ info.Completed }}
          </div>
        </div>
        <el-table :data="list" style="width: 100%">
          <el-table-column prop="" label="操作" width="90">
            <template slot-scope="scope">
              <span class="look" @click="openDetail(scope)">查看</span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="序号" width="60" type="index" :index="getIndex">
          </el-table-column>
          <el-table-column prop="NickName" label="姓名" width="180">
          </el-table-column>
          <el-table-column prop="Mobile" label="联系方式" width="200">
          </el-table-column>
          <el-table-column prop="Recorded" label="已打卡点位数量" width="200">
          </el-table-column>
        </el-table>
        <el-pagination v-if="total > 0" background layout="prev, pager, next" :total="total" :current-page="currentPage"
          :page-size="pageSize" @current-change="handleCurrentChange">
        </el-pagination>
      </div>
    </div>
    <div class="button_list" v-if="detail.StatusID == 2">
      <button style="background-color: #1E1B19;"  @click="save()">撤销发布</button>
    </div>
    <SelectPointDetail ref="SelectPointDetail"></SelectPointDetail>
  </el-drawer>
</template>

<script>
import SelectPointDetail from "./SelectPointDetail.vue";
export default {
  name: "cat_dialog",
  components: {
    SelectPointDetail
  },
  props: {},
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      detail: {},
      pointList: [],
      tabIndex: 0,
      info: {
        ApplyNbm: 0,
        Completed: 0
      },
      currentPage: 1,
      pageSize: 10,
      total: 0,
      list: []
    };
  },
  created() { },
  computed: {
    getImgUrl() {
      if (!this.detail.LineUrl || this.detail.LineUrl.length < 1) {
        return;
      }
      let arr = JSON.parse(this.detail.LineUrl);
      let obj = arr[0];
      return obj;
    },
    getMedal() {
      if (!this.detail.PicturePath || this.detail.PicturePath.length < 1) {
        return;
      }
      let arr = JSON.parse(this.detail.PicturePath);
      let obj = arr[0];
      return obj;
    }
  },
  watch: {},
  methods: {
    drawerOpen(data = null) {
      this.drawer = true;
      if (!data) {
        return;
      }
      this.detail = data;
      this.tabIndex = 0;
      this.detail.SortTypeID = String(data.SortTypeID);
      this.get_api_1303(data.ID);
      this.api_1324(data.ID);
      this.api_1325(data.ID);
    },
    // 获取大图上的点
    get_api_1303(ID) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1303,
          cellData: [
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建用户
            { name: "ID" }, // ID
            { name: "IsWorldMap" }, // IsWorldMap
            { name: "PointID" }, // 点位表ID
            { name: "Sort" }, // 排序
            { name: "WalkLineID" }, // 打卡路线ID
            { name: "Name" }, // Name
            { name: "x" }, // XPoint
            { name: "y" } // YPoint
          ],
          paramData: {
            WalkLineID: ID
          }
        },
        data => {
          if (data.status.code == 200) {
            let obj = JSON.parse(this.detail.LineUrl);
            let blw = obj[0].widthBl;
            let blh = obj[0].heightBl;

            data.content.queryData.map(v => {
              v.sx = v.x / blw;
              v.sy = v.y / blh;
              v.pw = 33 / blw;
            });

            data.content.queryData.sort((a, b) => {
              return a.Sort - b.Sort;
            });

            this.pointList = data.content.queryData;
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    save() {
      this.$confirm(`确定撤销当前已发布的线路吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        // type: 'warning'
        center: true
      })
        .then(res => {
          this.update_api_1291();
        })
        .catch(() => {
          console.log("取消了");
        });
    },
    // 保存线路
    update_api_1291() {
      let cellDate = [
        { name: "Status", defaultValue: 3 }, // 路线状态（1未发布  2已发布  3 取消）
        {
          name: "UpdateTime",
          defaultValue:
            new Date().toJSON().substring(0, 10) +
            " " +
            new Date().toTimeString().substring(0, 8)
        },
        { name: "UpdateUserID", defaultValue: this.octopus.passport.id }
      ];

      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1291,
          type: "UPDATE",
          value: this.detail.ID,
          cellData: cellDate,
          paramData: {}
        },
        data => {
          if (data.status.code == 200) {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$emit("reload");
            this.drawer = false;
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    api_1324(ID) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1324,
          cellData: [
            { name: "ApplyNbm" }, // 参加人数
            { name: "Completed" } // 完成人数
          ],
          paramData: {
            WalkLineID: ID
          }
        },
        data => {
          if (data.status.code == 200) {
            this.info = {
              ApplyNbm: data.content.queryData[0]
                ? data.content.queryData[0].ApplyNbm
                : 0,
              Completed: data.content.queryData[0]
                ? data.content.queryData[0].Completed
                : 0
            };
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    api_1325(ID) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1325,
          cellData: [
            { name: "ID" }, // ID
            { name: "Mobile" }, //  联系方式
            { name: "NickName" }, // 姓名
            { name: "Recorded" } // 已打卡点位数量
          ],
          paramData: {
            WalkLineID: ID
          },
          pageData: {
            index: this.currentPage,
            rowSize: this.pageSize
          }
        },
        data => {
          if (data.status.code == 200) {
            this.list = data.content.queryData;
            this.total = data.content.pageData.totalRows;
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.api_1325(this.detail.ID);
    },
    openDetail(scope) {
      this.$refs.SelectPointDetail.drawerOpen(scope.row, this.detail.ID);
    }
  }
};
</script>
<style scoped>
.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_title {
  box-shadow: 0px 5px 5px rgb(230 228 228 / 30%);
  padding-bottom: 1rem;
  font-size: 1.6rem;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 2rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.button_box {
  margin-top: 1rem;
  padding: 0 3rem;
  display: flex;
}

.drawer_content {
  overflow-y: auto;
  margin-top: 1.5rem;
  height: calc(100vh - 11rem);
  padding: 0 3rem;
  width: 100%;
  padding-bottom: 1rem;
}

.drawer_content .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_content .driver-title {
  margin-top: 1em;
}

.content-box {
  display: flex;
  align-items: center;
  margin: 2rem 0 2rem 2em;
}

.mt-10 {
  margin-top: 10rem;
}

.content-box .label {
  width: 25%;
  font-size: 1.6rem;
}

.content-box .label .label-bold {
  font-size: 1.8rem;
  font-weight: bold;
}

.content-box .desc {
  flex: 1;
  font-size: 1.6rem;
}

.list-box {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

.list-box {
  line-height: 4rem;
  margin-top: 2rem;
}

.list-box .left {
  width: 20%;
  font-size: 1.5rem;
}

.list-box .right {
  width: 80%;
  position: relative;
}

.button_list {
  margin-top: 1rem;
  display: flex;
  justify-content: end;
  position: absolute;
  background-color: #ffff;
  bottom: 1rem;
  width: calc(100% - 7rem);
}

.button_list button {
  border: none;
  height: 4rem;
  width: 12rem;
  border-radius: 1rem;
  margin-left: 1rem;
  color: #ffff;
  background-color: #f78c53;
  cursor: pointer;
}

.row {
  display: flex;
  flex-direction: row;
  align-items: center;
  border-bottom: 1px solid #f1f1f1;
}

.big-img {
  width: 100%;
}

.row .name {
  margin-right: 10px;
  min-width: 10vw;
}

.point {
  width: 24px;
  height: 24px;
  position: relative;
  margin-right: 10px;
}

.point img {
  width: 100%;
}

.point span {
  position: absolute;
  top: 0;
  left: 50%;
  line-height: 100%;
  transform: translate(-50%, 16%);
  color: #fff;
  display: inline-block;
}

.row .lat {
  min-width: 8vw;
  display: inline-block;
}

.row .lat span {
  padding: 0 10px;
}

.small-box {
  position: absolute;
  top: 0;
  left: 0;
  color: #fff;
}

.small {
  width: 100%;
}

.small-box span {
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translate(-50%, -28%);
}

.medal {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 16rem;
}

.medal img {
  width: 16rem;
}

.tab {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 20px;
}

.tab div:nth-child(1) {
  padding: 10px 30px;
  cursor: pointer;
  border-radius: 5px 0 0 5px;
  border: 1px solid #b0b0b0;
}

.tab div:nth-child(2) {
  padding: 10px 30px;
  cursor: pointer;
  border-radius: 0 5px 5px 0;
  border: 1px solid #b0b0b0;
  border-left: 0;
}

.look {
  cursor: pointer;
  border-radius: 5px;
  border: 1px solid #ececec;
  padding: 0px 10px;
}
</style>
